#!/bin/bash
{
# DietPi-Update pre-patches that need to run before new scripts are downloaded and/or before APT upgrades
# Created by MichaIng / micha@dietpi.com / https://dietpi.com/
# License: GPLv2 / https://github.com/MichaIng/DietPi#license

# Load DietPi-Globals
. /boot/dietpi/func/dietpi-globals
readonly G_PROGRAM_NAME='DietPi-Pre-patches'
G_CHECK_ROOT_USER
G_CHECK_ROOTFS_RW
G_INIT

# IMPORTANT: This script can be called with DietPi v6.17, hence assure compatibility!
# - Pre-v6.29: Create G_EXEC as G_RUN_CMD wrapper
declare -F G_EXEC > /dev/null || G_EXEC(){ G_RUN_CMD "$@"; }

# Update Jellyfin APT repo key: https://dietpi.com/phpbb/viewtopic.php?t=8703
if [[ -f '/etc/apt/trusted.gpg.d/dietpi-jellyfin.gpg' && $(date -u '+%Y%m%d' -r '/etc/apt/trusted.gpg.d/dietpi-jellyfin.gpg') -lt 20201216 ]]
then
	G_DIETPI-NOTIFY 2 'Updating Jellyfin APT repo key: https://dietpi.com/phpbb/viewtopic.php?t=8703'
	G_EXEC curl -sSfLO 'https://repo.jellyfin.org/jellyfin_team.gpg.key'
	G_EXEC gpg --dearmor -o /etc/apt/trusted.gpg.d/dietpi-jellyfin.gpg --yes jellyfin_team.gpg.key
	G_EXEC rm jellyfin_team.gpg.key
fi

exit 0
}
